package gui.view;

import java.awt.Component;
import java.awt.event.ActionEvent;

import javax.swing.Action;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.LookAndFeel;
import javax.swing.table.TableCellRenderer;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledEditorKit;

/**
 * 
 * @author D'Er'Nasherbrezon aka dernasherbrezon %)
 *
 */
public class MultiLineHeaderRenderer  extends JTextArea implements TableCellRenderer 
{

	JScrollPane m_scrollPane;
	
	public MultiLineHeaderRenderer()
	{
		setLineWrap(true);
		setWrapStyleWord(true);
		
		m_scrollPane = new JScrollPane(this);

		m_scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

		m_scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
	m_scrollPane.setBorder(null);

	}

	public Component getTableCellRendererComponent(JTable table,Object value,boolean isSelected,boolean hasFocus,int row, int col) 
	{
		setText((String)value);

		Action centerAlignAction = new StyledEditorKit.AlignmentAction("center-justify",StyleConstants.ALIGN_CENTER);

		selectAll();

		centerAlignAction.actionPerformed(new ActionEvent(this,ActionEvent.ACTION_PERFORMED, "center-justify"));
		
		return m_scrollPane;
	}
	
	public void updateUI()
	{
		super.updateUI();

		LookAndFeel.installColorsAndFont(this,"TableHeader.background","TableHeader.foreground","TableHeader.font");

		LookAndFeel.installBorder(this, "TableHeader.cellBorder");
	}
}